﻿namespace DimensionsHelper.LanguageService.Syntax;

public class MetadataTemplate : Declaration
{
    private StringLiteral? _value;

    internal MetadataTemplate(SyntaxNode? parent, Identifier name) :
        base(SyntaxKinds.MetadataTemplate, SyntaxToken.Default, name, parent)
    {
    }

    /// <summary>
    ///     元数据模板值，只能是字符串，解析时需要尽可能地转换成字符串
    /// </summary>
    public StringLiteral? Value => _value;


    public MetadataTemplate Update(StringLiteral value)
    {
        SetChildNullableField(ref _value, value);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, NameIdentifier, Value);
    }
}


public static partial class NodeFactory
{
    public static MetadataTemplate CreateMetadataTemplate(SyntaxNode? parent, Identifier identifierName,
        StringLiteral? value)
    {
        MetadataTemplate template = new(parent, identifierName);
        if (value != null)
        {
            template.Update(value);
        }

        return template;
    }
}